package com.rowline.admin.module.study.thread;

/**
 * ClassName:ThreadSoftedTest
 * Created by 245167
 * on 2018/1/9  09:18
 * description:在t2的线程里面t1 的join方法，抢占时间片，
 * 然后在t3的线程里面，抢占t2的时间片，理应是 t3执行>t2执行>t1执行，
 * 可以到最后结果的时候，每次的结果都不尽相同
 */
public class ThreadSoftedTest {


    public static void main(String[] args) {
        final Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + " run 1");
            }
        },"T1");

        final Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try{
                    t1.join(10);
                    System.out.println(Thread.currentThread().getName() + " run 2");
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        },"T2");

        final Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                try{
                    t2.join(10);
                    System.out.println(Thread.currentThread().getName() + " run 3");
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        },"T3");

        t1.start();
        t2.start();
        t3.start();
    }

}
